﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;


namespace DataClass
{
    public class ASUIHelped
    {
        public static void FillDataToList(DataTable dataTable, ListControl list, string valueField, string textField)
        {
            list.DataSource = dataTable;
            list.ValueMember = valueField;
            list.DisplayMember = textField;
          
        }

        //bindField là code nguồn bind , bindValue la giá trị của code nguồn, list là nơi hiển thị, valueField là giá trị của itemList, textField là hiển thị của itemList
        public static void BindDataToList(string bindField, string bindValue, ListControl list, string valueField, string textField)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = "Bind"+ bindField;
            string parameterName = "@" + bindField;
            string parameterValue = bindValue;
            DataTable dataTable = new DataTable();
            
            dataTable = dataProvider.GetDataTable(parameterName, parameterValue);
            
            FillDataToList(dataTable, list, valueField, textField);
              
        }

        public static void BindDataToList(string Cmd,ListControl list, string valueField, string textField)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = Cmd;
            
            DataTable dataTable = new DataTable();

            dataTable = dataProvider.GetDataTable();

            FillDataToList(dataTable, list, valueField, textField);

        }

        //Bind data to ComboBox
        public static void BindDataToComboBox(string bindField, string bindValue, ComboBox cboBox, string valueField, string textField)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = "Bind" + bindField;
            string parameterName = "@" + bindField;
            string parameterValue = bindValue;
            DataTable dataTable = new DataTable();

            dataTable = dataProvider.GetDataTable(parameterName, parameterValue);

            FillDataToComboBox(dataTable, cboBox, valueField, textField);

        }

        public static void BindDataToComboBox(string Cmd,ComboBox cboBox, string valueField, string textField)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = Cmd;
           
            DataTable dataTable = new DataTable();

            dataTable = dataProvider.GetDataTable();

            FillDataToComboBox(dataTable, cboBox, valueField, textField);

        }

        public static void BindDataToComboBox(string Cmd,string parameterName,string parameterValue, ComboBox cboBox, string valueField, string textField)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = Cmd;

            DataTable dataTable = new DataTable();

            dataTable = dataProvider.GetDataTable(parameterName,parameterValue);

            FillDataToComboBox(dataTable, cboBox, valueField, textField);

        }

        public static void BindDataToComboBox(string Cmd, string[] parameterNames, object[] parameterValues, ComboBox cboBox, string valueField, string textField)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = Cmd;

            DataTable dataTable = new DataTable();

            dataTable = dataProvider.GetDataTable(parameterNames, parameterValues);

            FillDataToComboBox(dataTable, cboBox, valueField, textField);

        }

        public static void FillDataToComboBox(DataTable dataTable, ComboBox cboBox, string valueField, string textField)
        {
            cboBox.DataSource = dataTable;
            cboBox.ValueMember = valueField;
            cboBox.DisplayMember = textField;

        }

        public static void BindDataToGridView(string CmdName, DataGridView dataGridView)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = CmdName;
            DataTable dataTable = new DataTable();
            dataTable = dataProvider.GetDataTable();
            FillDataToGridView(dataTable, dataGridView);
        }

        public static void BindDataToGridView(string CmdName, DataGridView dataGridView,int InvisibleColumn)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = CmdName;
            DataTable dataTable = new DataTable();
            dataTable = dataProvider.GetDataTable();
            FillDataToGridView(dataTable, dataGridView,InvisibleColumn);
        }

        public static void BindDataToGridView(string CmdName, string parameterName, string parameterValue, DataGridView dataGridView)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = CmdName;
            DataTable dataTable = new DataTable();
            dataTable = dataProvider.GetDataTable(parameterName, parameterValue);
            FillDataToGridView(dataTable, dataGridView);
        }

        public static void BindDataToGridView(string CmdName, string parameterName, string parameterValue, DataGridView dataGridView, int InvisibleColumn)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = CmdName;
            DataTable dataTable = new DataTable();
            dataTable = dataProvider.GetDataTable(parameterName, parameterValue);
            FillDataToGridView(dataTable, dataGridView,InvisibleColumn);
        }

        public static void BindDataToGridView(string CmdName, string[] parameterNames, object[] parameterValues, DataGridView dataGridView, int InvisibleColumn)
        {
            ASDataProvider dataProvider = new ASDataProvider();
            dataProvider.CommandType = CommandType.StoredProcedure;
            dataProvider.CommandText = CmdName;
            DataTable dataTable = new DataTable();
            dataTable = dataProvider.GetDataTable(parameterNames, parameterValues);
            FillDataToGridView(dataTable, dataGridView, InvisibleColumn);
        }

        public static void FillDataToGridView(DataTable dataTable, DataGridView dataGridView)
        {
            dataGridView.DataSource = dataTable;
           
        }

        public static void FillDataToGridView(DataTable dataTable, DataGridView dataGridView, int DisableColumnsIndex)
        {
            dataGridView.DataSource = dataTable;
            dataGridView.Columns[DisableColumnsIndex].Visible = false;

        }

        public static void ShowMessageBox(Exception ex, string methodName)
        {
            MessageBox.Show(ex.Message, ASParameters.welcomeMessage + "[" + methodName + "]");
        }




        
    }
}
